#!/bin/bash

# 1：关闭防火墙  ###
echo "关闭防火墙,并设置网络模式。"
systemctl stop firewalld
systemctl disable firewalld &&gt; /dev/null
setenforce 0
sed -i '7s/enforcing/disabled/g' /etc/selinux/config

# 2：定义网络
sed -i '7a alias cdnet="cd /etc/sysconfig/network-scripts" ' /root/.bashrc
sed -i 's/quiet/quiet net.ifnames=0/' /etc/default/grub # 恢复eth模式
cd /etc/sysconfig/network-scripts
mv ifcfg-ens3* ifcfg-eth0

cat &gt; ifcfg-eth0 &lt;&lt; EOF
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.10.250
PREFIX=24
GATEWAY=192.168.10.2
EOF

# 3：YUM仓库设置 #
# 需确保光盘已经点亮
echo "开始设置本地和epel仓库,请耐心等待..."
mkdir /media/cdrom
mount /dev/sr0 /media/cdrom/ &&gt; /dev/null
echo "/dev/sr0 /media/cdrom                    iso9660    defaults        0 0" &gt;&gt; /etc/fstab
cd /etc/yum.repos.d/
mkdir backup
mv CentOS-Media.repo local.repo
mv CentOS-* backup/
cat &gt;&gt; local.repo &lt;&lt; EOF
[local]
name=local
baseurl=file:///media/cdrom/
gpgcheck=0
enabled=1
EOF

yum clean all &&gt; /dev/null && yum makecache &&gt; /dev/null
yum -y -q install vim psmisc gcc gcc-c++ lrzsz openssl-devel pcre-devel net-tools wget curl zlib-devel unzip &&gt; /dev/null

# epel源
wget http://mirrors.aliyun.com/repo/Centos-7.repo &&gt; /dev/null
wget http://mirrors.aliyun.com/repo/epel-7.repo &&gt; /dev/null
yum -y -q install htop glances iftop dstat ntsysv &&gt; /dev/null && echo "YUM仓库完全设置完毕"
cd /etc/yum.repos.d/
mv Centos-7.repo epel-7.repo backup/

# 重启服务器进行生效 #
grub2-mkconfig -o /boot/grub2/grub.cfg &&gt; /dev/null
echo "恭喜你,设置成功,马上重启生效!"
reboot